﻿using Assets.Game.scripts.ui.models;
using Engine.Entities.Character;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Assets.Game.scripts.ui.controllers {

    [RequireComponent(typeof(CharacterListWidgetModel))]
    class CharacterListWidgetController : MonoBehaviour {

        public UITable agentsTable;
        public GameObject agentItemRenderer;

        public void Start() {
            CharacterListWidgetModel model = this.GetComponent<CharacterListWidgetModel>();

            if (this.agentsTable != null && this.agentItemRenderer!=null) {
                foreach (SteveBrain agent in model.agents) {
                    SteveModel agentModel = agent.model;
                    GameObject itemRendererInstance =  NGUITools.AddChild(this.agentsTable.gameObject, this.agentItemRenderer);

                    CharacterItemRendererModel itemModel = itemRendererInstance.GetComponent<CharacterItemRendererModel>();
                    if (itemModel != null) {
                        itemModel.data = agent;
                    }
                }
            }
        }

        public void onClose() {
            NGUITools.Destroy(this.gameObject);
            print("exiting building widget");
        }
    }
}
